#include "TestGame.h"
#include "Timer.h"

TestGame::TestGame(HINSTANCE hInstance) : Game(hInstance){
	
}




bool TestGame::OnStartUp(){
	//t = new Triangle(SetVertex(-50, 0, 0, 152, 20, 71), SetVertex(50, 0, 0, 152, 20, 71), SetVertex(0, 50, 0, 152, 20, 71), 2, 4);

	//b = new Box(SetVertex(-50, -150, 0, 23, 17, 71), SetVertex(0, -150, 0, 23, 17, 71), SetVertex(-10, -50, 0, 23, 17, 71), SetVertex(40, -50, 0, 23, 17, 71), 1, 2);

	//c = new Circle(90, 0, 0, 255, 0, 0);

	importer = new Importer(m_renderer);
	importer->Load("Asuna.xml", *this);

	s = NULL;
	s2 = NULL;
	GetEntity(&s,"character");
	GetEntity(&s2,"character2");
	return true;
}




bool TestGame::OnLoop(){
	//t->Draw(m_renderer);
	//b->Draw(m_renderer);
	//c->Draw(m_renderer);
	s2->SetAnimation("Idle");

	if(dInput->keyDown(Engine::Input::KEY_DOWN)){
		s2->SetPosition(s2->GetPositionX(), s2->GetPositionY() -  FRAME_SPEED * timer.GetDT());
		s2->SetAnimation("WalkingSouth");
	}
	else if(dInput->keyDown(Engine::Input::KEY_UP)){
		s2->SetPosition(s2->GetPositionX(), s2->GetPositionY() +  FRAME_SPEED * timer.GetDT());
		s2->SetAnimation("WalkingNorth");
	}
	else if(dInput->keyDown(Engine::Input::KEY_RIGHT)){
		s2->SetPosition(s2->GetPositionX()  +  FRAME_SPEED * timer.GetDT(), s2->GetPositionY());
		s2->SetAnimation("WalkingEast");
	}
	else if(dInput->keyDown(Engine::Input::KEY_LEFT)){
		s2->SetPosition(s2->GetPositionX() - FRAME_SPEED * timer.GetDT(), s2->GetPositionY());
		s2->SetAnimation("WalkingWest");
	}


	if(s != NULL)
		s->SetAnimation("WalkingSouth-west");

	if(dInput->mouseDown(Engine::Input::MouseButton::MB_1))
		s->SetPosition(s->GetPositionX() + dInput->mouseRelPosX(), s->GetPositionY() - dInput->mouseRelPosY());

	for(unsigned int i = 0; i < m_pkEntities.size(); i ++){
		m_pkEntities[i]->Update(timer);
		m_pkEntities[i]->Draw(m_renderer);
	}
	

	return true;
}




bool TestGame::OnShutDown(){
	return true;
}